package cmd

import (
	"gitee.com/xuender/se"
	"github.com/fatih/color"
	"github.com/spf13/cobra"
)

// nolint: gochecknoinits
func init() {
	minCmd := &cobra.Command{
		Use:     "min",
		Short:   "压缩索引",
		Long:    `减少索引尺寸`,
		Aliases: []string{"m"},
		Run: func(cmd *cobra.Command, args []string) {
			ctx := se.NewContext(cmd)

			color.White(
				"数据库目录: %s",
				ctx.DataBasePath,
			)
			color.Cyan("缩小前索引尺寸: %s", se.FormatFileSize(se.Size(ctx.DataBasePath)))

			app := se.InitApp(ctx)

			app.Min()
			app.Close()
			color.Red("缩小后索引尺寸: %s", se.FormatFileSize(se.Size(ctx.DataBasePath)))
		},
	}

	rootCmd.AddCommand(minCmd)
}
